//  $(function() {
//             $( "#opener" ).live("click", function() {
//                    $( "#dialog" ).dialog("open");
//                });
//
//                $("#mateusz").live("click", function(){
//                        
//                        $( "#dialog2" ).dialog();
//                });
//      });

$(document).ready(function() {
   //When you click on a link with class of poplight and the href starts with a # 
$('#usterki').live("click",function() {
   var popID = $(this).attr('rel'); //Get Popup Name

   //Fade in the Popup and add close button
   $('#' + popID).fadeIn().css({ 'width': 1000, 'height': 500 }).prepend('<a class="close" href="#"><img class="btn_close" title="Zamknij okno" src="resources/img/close_pop.png" alt="Zamknij" /></a>');

   //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
   var popMargTop = ($('#' + popID).height() + 80) / 2;
   var popMargLeft = ($('#' + popID).width() + 80) / 2;

   //Apply Margin to Popup
   $('#' + popID).css({
       'margin-top' : -popMargTop,
       'margin-left' : -popMargLeft
   });

   //Fade in Background
   $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
   $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 

   return false;
});

$('#pokaznagrody').live("click",function() {
   var popID = $(this).attr('rel'); //Get Popup Name

   //Fade in the Popup and add close button
   $('#' + popID).fadeIn().css({ 'width': 1000, 'height': 500 }).prepend('<a class="close" href="#"><img class="btn_close" title="Zamknij okno" src="resources/img/close_pop.png" alt="Zamknij" /></a>');

   //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
   var popMargTop = ($('#' + popID).height() + 80) / 2;
   var popMargLeft = ($('#' + popID).width() + 80) / 2;

   //Apply Margin to Popup
   $('#' + popID).css({
       'margin-top' : -popMargTop,
       'margin-left' : -popMargLeft
   });

   //Fade in Background
   $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
   $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 

   return false;
});

$('#tankowania').live("click",function() {
   var popID = $(this).attr('rel'); //Get Popup Name

   //Fade in the Popup and add close button
   $('#' + popID).fadeIn().css({ 'width': 1000, 'height': 500 }).prepend('<a class="close" href="#"><img class="btn_close" title="Zamknij okno" src="resources/img/close_pop.png" alt="Zamknij" /></a>');

   //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
   var popMargTop = ($('#' + popID).height() + 80) / 2;
   var popMargLeft = ($('#' + popID).width() + 80) / 2;

   //Apply Margin to Popup
   $('#' + popID).css({
       'margin-top' : -popMargTop,
       'margin-left' : -popMargLeft
   });

   //Fade in Background
   $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
   $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 

   return false;
});

$('#rezerwuj').live("click",function() {
    var that = $(this);
    var hour = that.html();
    $("#formHour").val(hour);
    var firstBusStop = that.parent().find('td').eq(0).html();
    $("#formbusStopFirstId").val(firstBusStop);
    
    var that = $(this);
    var hour = that.html();
    $("#formHour2").val(hour);
    var firstBusStop2 = that.parent().find('td').eq(0).html();
    $("#formbusStopFirstId2").val(firstBusStop2);
    

   var popID = $(this).attr('rel'); //Get Popup Name

   //Fade in the Popup and add close button
   $('#' + popID).fadeIn().css({ 'width': 800, 'height': 500 }).prepend('<a class="close" href="#"><img class="btn_close" title="Zamknij okno" src="resources/img/close_pop.png" alt="Zamknij" /></a>');

   //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
   var popMargTop = ($('#' + popID).height() + 80) / 2;
   var popMargLeft = ($('#' + popID).width() + 80) / 2;

   //Apply Margin to Popup
   $('#' + popID).css({
       'margin-top' : -popMargTop,
       'margin-left' : -popMargLeft
   });

   //Fade in Background
   $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
   $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 

   return false;
});


//Close Popups and Fade Layer
$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
   $('#fade , .popup_block').fadeOut(function() {
       $('#fade, a.close').remove();  //fade them both out
   });
   return false;
});
});

